import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:myflutterproject/views/myredtag.dart';

import 'myblacktag.dart';

class SceniCard2 extends StatelessWidget {
  final String title;
  final String intro;
  final String address;
  final String price;
  final String oldprice;
  final String discount;
  final List<String> tag;
  final List<String> imageUrls;

  SceniCard2(this.title, this.intro, this.address, this.price, this.discount,
      this.tag, this.imageUrls, this.oldprice);

  @override
  Widget build(BuildContext context) {

    final imageWidth1 = (MediaQuery.of(context).size.width -70) / 3;
    final imageWidth2 = imageWidth1*2+10;
    final imageHeight = imageWidth1 - 20;

    return Card(
      color: Colors.white,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(10),
      ),
      margin: EdgeInsets.only(top: 10, left: 10, right: 10),
      elevation: 0.0,
      child: Padding(
        padding: EdgeInsets.all(10),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Text('$title',style: TextStyle(
                    fontSize: 15,
                    color: Colors.black,
                    fontWeight: FontWeight.bold)),
                //右侧删除按钮
                Container(
                  width: 30,
                  height: 30,
                  child: IconButton(
                    icon: Icon(Icons.highlight_off,size: 20,), 
                    onPressed: () { print('删除'); },
                  ),
                ),
              ],
            ),
            SizedBox(height: 5,),
            //介绍
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Text('$intro',style: TextStyle(fontSize: 10,color: Color(0xFF1D1D1D)),),
                Text('$address',style: TextStyle(fontSize: 10,color: Color(0xFF1D1D1D)),),
              ],
            ),
            SizedBox(height: 5,),
            //价格 折扣 tag
            Row(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.end,
              children: <Widget>[
                Text(
                  '¥',
                  style: TextStyle(fontSize: 10, color: Color(0xFFE54E45)),
                ),
                Text(
                  '$price',
                  style: TextStyle(fontSize: 13, color: Color(0xFFE54E45),fontWeight: FontWeight.bold),
                ),
                Text(
                  '¥$oldprice',
                  style: TextStyle(fontSize: 10, color: Color(0xFF1D1D1D),decoration: TextDecoration.lineThrough),
                ),
                SizedBox(width: 5,),
                MyTag('$discount', 3),
                SizedBox(width: 5,),
                Row(
                  children: _tagBody(tag),
                ),
              ],
            ),
            //图片
            Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                _buildImage(imageWidth2,imageHeight*2,imageUrls[1]),
                Column(
                  children: <Widget>[
                    _buildImage(imageWidth1,imageHeight,imageUrls[1]),
                    _buildImage(imageWidth1,imageHeight,imageUrls[2]),
                  ],
                ),
              ],
            ),

          ],
        ),
      ),
    );
  }

  List<Widget> _tagBody(List<String> tag){
    List<Widget> titleTag = <Widget>[];
    for(int i=0;i<tag.length;i++){
      titleTag.add(MyBlackTag(tag[i], 3));
      titleTag.add(SizedBox(width: 5,));
    }
    return titleTag;
  }
  Widget _buildImage(double width, double height, String imageUrl) {
    return Card(
      color: Colors.transparent,
      elevation: 0.0,
      child: ClipRRect(
        borderRadius: BorderRadius.circular(10.0),
        child: Image.network(
          imageUrl,
          fit: BoxFit.fill,
          width: width,
          height: height,
        ),
      ),
    );
  }
}
